public class _11盛最多水的容器 {
    public static int maxArea(int[] height) {
        int s = 0;
        for (int i = 0; i < height.length; i++) {
            for (int j = 0; j < i; j++) {
                s = Math.max(s, (i - j) * Math.min(height[i], height[j]));
            }
        }
        return s;
    }

    public static void main(String[] args) {
        int[] ints = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        int i = maxArea2(ints);
        System.out.println(i);
    }

    public static int maxArea2(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int r = 0;
        while (right >= left) {
            int s = (right - left) * Math.min(height[left], height[right]);
            if (height[left] < height[right]) {
                left++;
            } else {
                right--;
            }
            r = Math.max(r, s);
        }
        return r;

    }
}
